package com.robotic.minio;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

//@RestController
//@RequestMapping("/files")
public class FileController {

    //@Autowired
    private MinioService minioService;

    /**
     * 文件上传接口
     * 上传成功后返回文件的完整对象名 (e.g., "math/your-uuid.jpg")
     */
    @PostMapping("/upload")
    public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            String objectName = minioService.uploadFile(file);
            return ResponseEntity.ok("上传成功！对象名称: " + objectName);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().body("上传失败: " + e.getMessage());
        }
    }

}
